﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Showroom.DAL;
namespace Showroom.BLL
{
    public class CategoryProduct : _CategoryProduct
    {
        public static string GetListCurrentProductID(int CategoryID)
        {
            try
            {
                string sListID = "0123456789";
                CategoryProduct cProds = new CategoryProduct();
                cProds.Where.CategoryID.Value = CategoryID;
                cProds.Query.Load();
                for (int i = 0; i < cProds.RowCount; i++)
                {
                    sListID += "," + cProds.s_ProductID;
                    cProds.MoveNext();
                }
                return sListID.Trim(',');
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        public static void DeleteAllProducts(int CategoryID)
        {
            try
            {
                CategoryProduct cProds = new CategoryProduct();
                cProds.Where.CategoryID.Value = CategoryID;
                cProds.Query.Load();
                do
                {
                    cProds.MarkAsDeleted();
                }
                while (cProds.MoveNext());
                cProds.Save();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        public static void DeleteProductByID(int ID)
        {
            try
            {
                CategoryProduct cProds = new CategoryProduct();
                cProds.LoadByPrimaryKey(ID);
                cProds.MarkAsDeleted();
                cProds.Save();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
    }
}
